﻿using QFramework;
using UnityEngine;

namespace ProjectMyFarmAndShe
{
    public class GrapeSeedTool : ITool,IController
    {
        public string Name => "葡萄工具";
        public string Key => "GrapeSeedTool";
        public ToolType Type => ToolType.Speed;
        public float UseBrawn => 3.2f;

        public void Use(Vector3Int pos,DynaGrid<GridData> grids)
        {
            var gridData = grids[pos.x, pos.y];

            if (gridData == null || gridData.PlantItem != null)
            {
                return;
            }
            
            Global.Brawn.Value -= UseBrawn;
            
            var canUse = this.GetSystem<IToolbarSystem>().SubToolbarData(Key,1);
            if (!canUse) return;
            
            Global.Brawn.Value -= UseBrawn;
            AudioKit.PlaySound("resources://PlantPlace");
            
            var plant = ResController.Default.GrapePlantItem.Instantiate()
                .Position2D(new Vector2(pos.x + 0.5f,pos.y + 0.5f))
                .Show();

            gridData.SetPlant(plant);
            plant.GridData = gridData;
        }

        public IArchitecture GetArchitecture()
        {
            return Global.Interface;
        }
    }
}